package ch02;

import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args) {
        //猜数字
        //1.生成一个随机数
        int random=(int)(Math.random()*100+1);
        Scanner scan=new Scanner(System.in);


        for( int count=1; true ;count++){
            System.out.println("请输入一个数字：");
            int num=scan.nextInt();
            if(num==random){
                System.out.println("恭喜你，猜对了 " +count);
                break;
            }else {
                if(random>num){
                    System.out.println("猜小了");
                }else {
                    System.out.println("猜大了");
                }

            }
        }
    }
}
